package com.ruoyi.web.controller.goods;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.goods.domain.Brand;
import com.ruoyi.goods.domain.BrandPerson;
import com.ruoyi.goods.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

// 品牌
@RestController
@RequestMapping("/brand")
public class BrandController extends BaseController {

    @Autowired
    private BrandService brandService;

    @RequestMapping("/getBarandList")
    public TableDataInfo getList(HttpServletRequest request) {

        LoginUser loginUser = getLoginUser();
        SysUser user = loginUser.getUser();
        long deptParentId = user.getDept().getParentId();
        long deptId = 0;
        if(deptParentId != 0){
            deptId = deptParentId;
        }
        return getDataTable(brandService.getBarandList(Math.toIntExact(deptId)));
    }

    @RequestMapping("/getBarandAllList")
    public TableDataInfo getBarandAllList() {

        return getDataTable(brandService.getBarandList(0));
    }

    @RequestMapping("/getBrandPersonList")
    public TableDataInfo getBrandPersonList(int brandId) {
//        startPage();
        return getDataTable(brandService.getBrandPersonList(brandId));
    }

    // 新增品牌数据
    @PostMapping("/insertBrand")
    public AjaxResult insertBrand(Brand brand) {

        return success(brandService.insertBrand(brand));
    }

    // 新增品牌子类数据
    @PostMapping("/insertBrandPerson")
    public AjaxResult insertBrandPerson(BrandPerson branchPerson) {

        return success(brandService.insertBrandPerson(branchPerson));
    }

    //  修改品牌信息
    @PostMapping("/updateBrand")
    public AjaxResult updateBrand(Brand brand) {
        return success(brandService.updateBrand(brand));
    }

    //  修改品牌子分类信息
    @PostMapping("/updateBrandPerson")
    public AjaxResult updateBrandPerson(BrandPerson branchPerson) {
        return success(brandService.updateBrandPerson(branchPerson));
    }

    @PostMapping("/delBrandByIds/{ids}")
    public AjaxResult delBrandByIds(@PathVariable Long[] ids) {
        return success(brandService.delBrandByIds(ids));
    }

    @PostMapping("/delBrandPersonByIds/{ids}")
    public AjaxResult delBrandPersonByIds(@PathVariable Long[] ids) {
        return success(brandService.delBrandPersonByIds(ids));
    }

}
